package sddz.foodmanage.dialog;

import android.app.Activity;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import android.widget.TextView;

import sddz.foodmanage.R;
import sddz.foodmanage.base.BaseDialog;


/**
 * Created by zhanglei on 2017/4/6 0006.
 * 当用户未登录时显示的DiaLog
 */

public class BindCardDiaLog extends BaseDialog implements View.OnClickListener{

    private Activity mActivity;
    private PopupWindow popupWindow;
    private View view;
    private TextView titleView, okView, cancelView;

    public BindCardDiaLog(Activity mActivity) {
        super(mActivity);
        this.mActivity = mActivity;

        initView();
        initListener();
    }

    private void initListener() {
        popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                setAlpha(1f);
            }
        });

        okView.setOnClickListener(this);
        cancelView.setOnClickListener(this);
    }

    private void initView() {
        view = LayoutInflater.from(mActivity).inflate(R.layout.login_dialog_layout, null);
        titleView = (TextView) view.findViewById(R.id.dialog_title);
        okView = (TextView) view.findViewById(R.id.dialog_ok);
        cancelView = (TextView) view.findViewById(R.id.dialog_cancel);

        titleView.setText(R.string.no_bind_card);
        titleView.getPaint().setFakeBoldText(true);
        okView.setText(R.string.bind_card);

        popupWindow = new PopupWindow(view, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        popupWindow.setFocusable(true);
        popupWindow.setTouchable(true);
        popupWindow.setBackgroundDrawable(mActivity.getResources().getDrawable(R.drawable.login_dialog_shape));
    }

    /**
     * 显示dialog
     */
    public void showDiaLog() {
        popupWindow.showAtLocation(view, Gravity.CENTER, 0, 0);
        setAlpha(0.4f);
    }

    /**
     * 隐藏dialog
     */
    public void hideDiaLog() {
        popupWindow.dismiss();
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            //跳转到绑卡界面
            case R.id.dialog_ok:
//                mActivity.startActivity(new Intent(mActivity, BindCardActivity.class));
//                mActivity.overridePendingTransition(R.anim.bamboy_right_in, R.anim.bamboy_n_left_out);
                hideDiaLog();
                break;
            case R.id.dialog_cancel:
                hideDiaLog();
                break;
        }
    }
}

